<template>
	<div class="app-loading">
	    <div class="app-loading-wrap">
	      <div class="app-loading-title">
	        <image src="@/static/images/logo.png" class="app-loading-logo" mode="widthFix"  />
			<view class="lodingBox">
				<image class="loding" src="@/static/images/loding.gif" mode="widthFix"></image>
			</view>
	        <!-- <div class="app-loading-title">安全连接正在建立中...</div> -->
	        <div class="app-loading-title">正在为您进行身份验证</div>
	      </div>
		  
	      <!-- <div class="app-loading-item">
	        <div class="app-loading-outter"></div>
	        <div class="app-loading-inner"></div>
	      </div> -->
	    </div>
	</div>
</template>

<script>
	import Verify from "@/components/verifition/Verify"
	import {getSimpleDictDataList} from '@/api/system/dict.js'
	import {setDictOptions} from '@/utils/auth.js'
	import {socialLogin} from '@/api/common.js'
	import { setToken, removeToken,setTenantId,getTenantId } from '@/utils/auth'
	export default {
		data() {
			return {
				redirect:'/',
			};
		},
		methods:{
			/* 第三方登录使用 */
			async tryLogin(){
				try {
				    const type = '35'
				    this.redirect = this.getRedirect()
				    // const tenantId = this.getUrlValue('tenantId')
					const tenantId = getTenantId('tenantId')
				    const code = this.getUrlValue('code')
				    const state = this.getUrlValue('state')
				    const res = await socialLogin(type, code, state, tenantId)
					setToken(res.data)
					this.loginSuccess()
				} catch (err) {
					  console.log(err)
				}
			},
			//方法:用来提取code
			getUrlValue(name) {
			  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) || null
			},
			// 登录成功后，处理函数
			loginSuccess(result) {
				// 设置用户信息
				this.$store.dispatch('GetInfo').then(async res => {
					let info = await getSimpleDictDataList();
					setDictOptions(info.data)
					this.$tab.reLaunch(this.redirect)
				})
			},
			// 获取重定向地址
			getRedirect(){
				let url = decodeURIComponent(location.href)
				let arr =  url.split('&redirect=')
				let pages = arr[1].replace('/#/','/');
				return pages
				// this.$tab.reLaunch(pages)
			},
		},
		onLoad(option) {
			const code = this.getUrlValue('code')
			if(code){
				this.tryLogin()
			}
		}
	}
</script>

<style lang="less" scoped>
.wxLogin{
	width: 100%;
	min-height: 100vh;
	background-color: #fff;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	font-size: 30rpx;
	
	
}
.app-loading {
  display: flex;
  width: 100%;
  height: 100vh;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  background: #f0f2f5;
  position: relative; /* 修改为相对定位 */
  padding: 40rpx;
  box-sizing: border-box;
  background-color: #fff;
}

.app-loading-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.app-loading-title {
  margin-bottom: 10px;
  font-size: 30rpx;
  font-weight: bold;
  text-align: center;
  color: #715050;
}

.app-loading-logo {
  width: 200rpx;
  margin: 0 auto 15px auto;
}

.app-loading-item {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 60px;
  vertical-align: middle;
  border-radius: 50%;
}

.app-loading-outter {
  position: absolute;
  width: 100%;
  height: 100%;
  border: 4px solid #2d8cf0;
  border-bottom: 0;
  border-left-color: transparent;
  border-radius: 50%;
  animation: loader-outter 1s cubic-bezier(0.42, 0.61, 0.58, 0.41) infinite;
}

.app-loading-inner {
  position: absolute;
  top: calc(50% - 20px);
  left: calc(50% - 20px);
  width: 40px;
  height: 40px;
  border: 4px solid #87bdff;
  border-right: 0;
  border-top-color: transparent;
  border-radius: 50%;
  animation: loader-inner 1s cubic-bezier(0.42, 0.61, 0.58, 0.41) infinite;
}

@keyframes loader-outter {
  0% {
	transform: rotate(0deg);
  }
  100% {
	transform: rotate(360deg);
  }
}

@keyframes loader-inner {
  0% {
	transform: rotate(0deg);
  }
  100% {
	transform: rotate(-360deg);
  }
}

.lodingBox{
	width: 100%;
	margin-bottom: 40rpx;
	image{
		width: 400rpx;
	}
}
</style>
